import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/read/controller.dart';
import 'package:get/get.dart';

class ReadingPageWidget extends StatelessWidget {
  int index;
  Color color;
  ReadingPageWidget({super.key, required this.index, required this.color});
  final controller = Get.find<ReadController>();

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
            width: double.infinity,
            height: double.infinity,
            padding: controller.state.padding,
            color: color,
            child: Stack(
              children: [
                Text(
                  controller.state.data.isNotEmpty
                      ? controller.state.data.substring(
                          controller.state.allPages[index],
                          controller.state.allPages[index + 1])
                      : "",
                  maxLines:
                      controller.state.maxTextHeight ~/ controller.textHeight,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      height: controller.state.fontHeight,
                      fontSize: controller.state.fontSize,
                      // height: 1.5,
                      color: const Color(0xff333333)),
                ),
              ],
            )),
        Positioned(
          child: Text("${index + 1}/${controller.state.allPages.length - 1}"),
          bottom: 10,
          right: 20,
        )
      ],
    );
  }
}
